/**
 * org.vz.product.data.collect.service.impl
 * @since : jdk 1.8
 */
package org.vz.product.collect.maintain.service.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.vz.product.collect.maintain.dao.AcquisitionTaskDao;
import org.vz.product.collect.maintain.domain.AcquisitionTask;
import org.vz.product.collect.maintain.service.AcquisitionTaskService;
import org.vz.product.collect.maintain.util.StringUtil;

/**
 * @author      chenhuaijin
 * @CreateTime  2017年7月29日 上午11:36:53
 * @version     1.0.0
 * @description TODO
 */
@Service
public class AcquisitionTaskServiceImpl implements AcquisitionTaskService{
	@Autowired
	private AcquisitionTaskDao acTaskDao;
	/* (non-Javadoc)
	 * @see org.vz.product.data.collect.service.AcquisitionTaskService#saveAcquisitionTask(org.vz.product.data.collect.domain.AcquisitionTask)
	 */
	@Transactional
	@Override
	public void saveAcquisitionTask(String code,List<Long> idKtrs) {
		for (Long idKtr : idKtrs) {
			AcquisitionTask acquisitionTask = new AcquisitionTask();
			acquisitionTask.setCode(StringUtil.uuid());
			acquisitionTask.setAcquisitioncode(code);
			acquisitionTask.setIdktr(idKtr);
			acquisitionTask.setLastexecutetime(new Timestamp((new Date()).getTime()));
			acTaskDao.insertTemplate(acquisitionTask);
		}
		
		
	}
	/* (non-Javadoc)
	 * @see org.vz.product.data.collect.service.AcquisitionTaskService#updateAcquisitionTask(org.vz.product.data.collect.domain.AcquisitionTask)
	 */
	@Transactional
	@Override
	public void updateAcquisitionTask(String code,List<Long> idKtrs) {
		AcquisitionTask acTaskQuery = new AcquisitionTask();
		acTaskQuery.setAcquisitioncode(code);
		List<AcquisitionTask> acquisitionTasks = acTaskDao.getSQLManager().select("acquisition.getActask",AcquisitionTask.class,acTaskQuery);
		for (AcquisitionTask acTask : acquisitionTasks) {
			acTaskDao.deleteById(acTask.getCode());
		}
		for (long idKtr : idKtrs) {
			AcquisitionTask acTask = new AcquisitionTask();
			acTask.setCode(StringUtil.uuid());
			acTask.setAcquisitioncode(code);
			acTask.setIdktr(idKtr);
			acTask.setLastexecutetime(new Timestamp((new Date()).getTime()));
			acTaskDao.insertTemplate(acTask);
		}
		
		
	}
	/* (non-Javadoc)
	 * @see org.vz.product.data.collect.service.AcquisitionTaskService#getByAcId(java.lang.String)
	 */
	/* (non-Javadoc)
	 * @see org.vz.product.data.collect.service.AcquisitionTaskService#deleteAcTask(java.lang.String)
	 */
	@Transactional
	@Override
	public void deleteAcTask(List<String> codes) {
		for (String code : codes) {
			AcquisitionTask acquisitionTask = new AcquisitionTask();
			acquisitionTask.setAcquisitioncode(code);
			
			List<AcquisitionTask> acTasks = acTaskDao.getSQLManager().select("acquisition.getActask", AcquisitionTask.class, acquisitionTask);
			for (AcquisitionTask acquisitionTask2 : acTasks) {
				acTaskDao.deleteById(acquisitionTask2.getCode());
			}
		}
		
	}
	/* (non-Javadoc)
	 * @see org.vz.product.data.collect.service.AcquisitionTaskService#getJobbyAcId(java.lang.String)
	 */
	@Override
	public List<AcquisitionTask> getJobbyAcId(String code) {
		AcquisitionTask acquisitionTask = new AcquisitionTask();
		acquisitionTask.setAcquisitioncode(code);		
		List<AcquisitionTask> acTasks = acTaskDao.getSQLManager().select("acquisition.getActask", AcquisitionTask.class, acquisitionTask);
		return acTasks;
	}


}
